package cn.tedu.hospitalgroupproject.server.content.controller;

import cn.tedu.hospitalgroupproject.server.common.pojo.vo.PageData;
import cn.tedu.hospitalgroupproject.server.common.web.JsonResult;
import cn.tedu.hospitalgroupproject.server.content.pojo.param.DoctorAddNewParam;
import cn.tedu.hospitalgroupproject.server.content.pojo.param.DoctorTitleAppLimitAddNewParam;
import cn.tedu.hospitalgroupproject.server.content.pojo.param.DoctorTitleAppLimitUpdateParam;
import cn.tedu.hospitalgroupproject.server.content.pojo.param.DoctorUpdateInfoParam;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DoctorListItemVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DoctorStandardVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DoctorTitleAppLimitListVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DoctorTitleAppLimitStandardVO;
import cn.tedu.hospitalgroupproject.server.content.service.IDoctorService;
import cn.tedu.hospitalgroupproject.server.content.service.IDoctorTitleAppLimitService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/management/doctorTitles/")
@Api(tags="1.4 管理部分-医生职称预约上限管理")
public class DoctorTitleAppLimitController {

    @Autowired
    private IDoctorTitleAppLimitService doctorTitleAppLimitService;


    public DoctorTitleAppLimitController() {
        log.info("创建医生职称上限控制对象");
    }

    @ApiOperation("添加医生职称")
    @ApiOperationSupport(order = 150)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctor_title_id", value = "医生职称ID", required = true, dataType = "long")
    })
    @PostMapping("/add-new")
    public JsonResult addNew(@Validated DoctorTitleAppLimitAddNewParam doctorTitleAppLimitAddNewParam) {
        log.debug("开始处理【新增医生职称预约上限数据】的请求，添加类：{}", doctorTitleAppLimitAddNewParam);
        doctorTitleAppLimitService.addNew(doctorTitleAppLimitAddNewParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除职称")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "职称ID", required = true, dataType = "long")
    })
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable @Range(min = 1, message = "删除职称数据失败，请提交合法的ID值！") Long id) {
        log.debug("开始处理【删除指定职称ID下数据】的请求，参数：{}", id);
        doctorTitleAppLimitService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改职称信息")
    @ApiOperationSupport(order = 350)
    @PostMapping("/{doctorTitleId:[0-9]+}/update/info")
    public JsonResult updateInfoById(@Validated DoctorTitleAppLimitUpdateParam doctorTitleAppLimitUpdateParam) {
        log.debug("开始处理【修改职称信息】的请求，参数：{}", doctorTitleAppLimitUpdateParam);
        doctorTitleAppLimitService.updateInfoById(doctorTitleAppLimitUpdateParam);
        return JsonResult.ok();
    }

    @ApiOperation("根据ID查询职称信息")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "职称ID", required = true, dataType = "long")
    })
    @GetMapping("/{id:[0-9]+}")
    public JsonResult getStandardById(@PathVariable @Range(min = 1, message = "获取职称信息失败，请提交合法的ID值！") Long id) {
        log.debug("开始处理【根据职称ID查询职称】的请求，参数：{}", id);
        DoctorTitleAppLimitStandardVO doctorTitleAppLimitStandardVO = doctorTitleAppLimitService.getStandardById(id);
        return JsonResult.ok(doctorTitleAppLimitStandardVO);
    }


    @ApiOperation("查询医生职称列表")
    @ApiOperationSupport(order = 420)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int"),
            @ApiImplicitParam(name = "queryType", value = "查询类型，当需要查询全部数据时，此参数值应该是all")
    })
    @GetMapping("/list")
    public JsonResult listDoctorTitle(Integer page, String queryType) {
        log.debug("开始处理【查询医生职称列表】请求，页码：{}", page);
        if (page == null) {
            page = 1;
        }
        Integer pageNum = page > 0 ? page : 1;
        PageData<DoctorTitleAppLimitListVO> pageData ;
        if ("all".equals(queryType)) {
            pageData = doctorTitleAppLimitService.list(1, Integer.MAX_VALUE);
        } else {
            pageData = doctorTitleAppLimitService.list(pageNum);
        }
        return JsonResult.ok(pageData);
    }

}
